package com.mapapp.flutter_mapapp.widget;

import android.content.Context;
import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.blankj.utilcode.util.SizeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.mapapp.flutter_mapapp.R;
import com.mapapp.flutter_mapapp.adapter.OperationAdapter;

import java.util.ArrayList;
import java.util.List;

import razerdp.basepopup.BasePopupWindow;

public class ErrorCorrectionPopWindow extends BasePopupWindow {
    private RecyclerView recyclerView;
    private static final String[] ERROR_CORRECTION_OPTIONS = {"合户", "分户", "其他", "纠错"};

    public ErrorCorrectionPopWindow(Context context) {
        super(context);

        init();
    }


    @Override
    public View onCreateContentView() {
        View popupById = createPopupById(R.layout.popup_error_correction);
        recyclerView = popupById.findViewById(R.id.rv_error_correction);
        return popupById;
    }


    private void init() {
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        List<OperationAdapter.ErrorCorrectionBean> items = new ArrayList<>();
        for (String errorCorrectionOption : ERROR_CORRECTION_OPTIONS) {
            OperationAdapter.ErrorCorrectionBean errorCorrectionBean = new OperationAdapter.ErrorCorrectionBean();
            errorCorrectionBean.setName(errorCorrectionOption);
            items.add(errorCorrectionBean);
        }
        OperationAdapter operationAdapter = new OperationAdapter(R.layout.dialog_error_correction, items);
        recyclerView.setAdapter(operationAdapter);
        operationAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                if (listener != null) {
                    listener.onClick(position);
                    dismiss();
                }
            }
        });
    }

    public interface OnItemClickListener {
        void onClick(int index);
    }

    private OnItemClickListener listener;

    public void setListener(OnItemClickListener listener) {
        this.listener = listener;
    }
}
